# -*- coding: utf-8 -*-
# @desc:
# @file: mongo_helper.py
# @author: Lin Jackey Lyu (me@linlyu.com)
# @date: 2018/7/27 19:08

from pymongo import MongoClient


class MongoHelper(object):

    def __init__(self, conf):
        client = MongoClient(host=conf["host"], port=conf["port"])
        self.mongodb = client[conf["db"]]

    def fetch_data(self, collection, keys):
        coll = self.mongodb.get_collection(collection)
        projection = {'_id': False}
        for key in keys:
            projection[key] = True
        cursor = coll.find(projection=projection)
        return cursor
